Dogclass Dog():
     """一次模拟小狗的简单尝试"""
     def __init__(self, name, age):
         """初始化属性name和age"""
         self.name = name
         self.age = age
     def sit(self):
         """模拟小狗被命令时蹲下"""
         print(self.name.title() + " is now sitting.")
     def roll_over(self):
         """模拟小狗被命令时打滚"""
         print(self.name.title() + " rolled over!")
 my_dog = Dog("willie", 6)
 your_dog = Dog("lucy", 3)
 print("my dog's name is " + my_dog.name.title() + ".")
 print("my dog is " + str(my_dog.age) + " years old.")
 my_dog.sit()
 my_dog.roll_over()
 print("\nyour dog's name is " + your_dog.name.title() + ".")
 your_dog.sit()
class Car():
    def __init__(self, make, model, year):
        self.make = make
        self.model = model
        self.year = year
        self.odometer_reading = 3
    def get_descriptive_name(self):
        long_name = str(self.year) + " " + self.make + " " + self.model
        return long_name.title()
    def update_odometer(self,mileage):
        # """将里程表读数设置为指定的值"""
        # self.odometer_reading = mileage
        """
        将里程表读数设置为指定的值，禁止将里程表读数往回调
        """
        if mileage >= self.odometer_reading:
            self.odometer_reading = mileage
        else:
            print("you can't roll back an odometer!")
    def increment_ododmeter(self, miles):
        """将里程表读数增加指定的量"""
        self.odometer_reading += miles
    def read_odometer(self):
        print("this car has " + str(self.odometer_reading) + " miles on it.")
my_used_car = Car("subaru", "outback", 2013)
print(my_used_car.get_descriptive_name())
my_used_car.update_odometer(23500)
my_used_car.increment_ododmeter(100)
my_used_car.read_odometer()


